import time
import signal

from service.service import Service
from service.logger import Logger

exit = False


def handler(signum, frame):
    print("")
    global exit
    exit = True


def title():
    # https://patorjk.com/software/taag
    print(
        r"""
     _                      _               _____                     _      
    | |    ___   __ _  __ _(_)_ __   __ _  | ____|_  ____ _ _ __ ___ | | ___ 
    | |   / _ \ / _` |/ _` | | '_ \ / _` | |  _| \ \/ / _` | '_ ` _ \| |/ _ \
    | |__| (_) | (_| | (_| | | | | | (_| | | |___ >  < (_| | | | | | | |  __/
    |_____\___/ \__, |\__, |_|_| |_|\__, | |_____/_/\_\__,_|_| |_| |_|_|\___|
                |___/ |___/         |___/                                    

    """
    )


def help():
    print("Usage: python main.py [--log <level>]")
    print("Options:")
    print(
        "  --log <level>   Set log level (spam, trace, verbose, debug, info, warning, error). Default is info."
    )


def main():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    title()

    help()

    logger = Logger()

    service = Service()
    service.init()
    service.start()
    while not exit:
        time.sleep(0.2)
    service.stop()
    service.deinit()


if __name__ == "__main__":
    main()
